import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 汇率定义-平台级
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function rateApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/exchange-rates") : 'exchange-rates';
}
/**
 * 查询汇率定义的数据
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 * @param {String} params.fromCurrencyCode - 币种代码
 * @param {String} params.fromCurrencyName - 币种名称
 * @param {String} params.toCurrencyCode - 兑换币种代码
 * @param {String} params.toCurrencyName - 兑换币种名称
 */


export function fetchRateData(_x) {
  return _fetchRateData.apply(this, arguments);
}
/**
 * 新增汇率定义
 * @param {Object} params - 参数
 * @param {String} params.enabledFlag - 启用标识
 * @param {String} params.startDate - 起始时间
 * @param {String} params.endDate - 结束时间
 * @param {String} params.fromCurrencyCode - 币种代码
 * @param {String} params.fromCurrencyName - 币种名称
 * @param {String} params.toCurrencyCode - 兑换币种代码
 * @param {String} params.toCurrencyName - 兑换币种名称
 * @param {String} params.rateTypeCode - 汇率类型代码
 * @param {String} params.rateTypeName - 汇率类型名称
 * @param {String} params.rate - 汇率值
 */

function _fetchRateData() {
  _fetchRateData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateApi()), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchRateData.apply(this, arguments);
}

export function createRate(_x2) {
  return _createRate.apply(this, arguments);
}
/**
 * 更新汇率定义
 * @param {Object} params - 参数
 * @param {String} params.enabledFlag - 启用标识
 * @param {String} params.startDate - 起始时间
 * @param {String} params.endDate - 结束时间
 * @param {String} params.fromCurrencyCode - 币种代码
 * @param {String} params.fromCurrencyName - 币种名称
 * @param {String} params.toCurrencyCode - 兑换币种代码
 * @param {String} params.toCurrencyName - 兑换币种名称
 * @param {String} params.rateTypeCode - 汇率类型代码
 * @param {String} params.rateTypeName - 汇率类型名称
 * @param {String} params.rate - 汇率值
 */

function _createRate() {
  _createRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateApi()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createRate.apply(this, arguments);
}

export function updateRate(_x3) {
  return _updateRate.apply(this, arguments);
}
/**
 * 生成交叉汇率
 * @param {object} params - 参数
 * @param {String} params.currencyCode - 币种代码
 * @param {String} params.rateTypeCode - 汇率类型代码
 * @param {String} params.rateDate - 兑换日期
 * @returns
 */

function _updateRate() {
  _updateRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateApi()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateRate.apply(this, arguments);
}

export function createCrossRate(_x4) {
  return _createCrossRate.apply(this, arguments);
}

function _createCrossRate() {
  _createCrossRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateApi(), "/cross-exchange-rate"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _createCrossRate.apply(this, arguments);
}